#!/usr/bin/env python

# What is the value of the first triangle number to have over five hundred divisors?
import math

def triangle_number():
    nature = 1
    tri = 1
    while 1:
        yield tri
        nature = nature + 1
        tri += nature

def tri_divisors_len(tri):
    return len([ x for x in range(1, tri) if tri % x == 0 ])


def count(num):
    c = 0
    for i in range(1, int(math.sqrt(num)) + 1):
        if num % i == 0:
            c += 2
    return c

def main():
    list = [ a*(a + 1) / 2 for a in range(1, 100000)]
    for i in list[500:]:
        if count(i) > 500:
            break
    print i

# 2010-03-31
if __name__ == "__main__":
    main()
    # profile.Profile.run('tri_divisors_len(100)')
